const http=require('http')
const fs = require('fs')
const url = require('url')

const path=require('path')
const server=http.createServer((req,res)=>{
    res.writeHead(200,{'Content-Type': 'text/plain;charset=utf-8'});

    // let myurl = req.url
    // console.log(req.url);

    // console.log(myurl);
        // let obj = url.parse(req.url);
        // console.log(obj);
        // console.log(req.method);
    
    let obj=url.parse(req.url,true);
    // console.log(obj);
    let query=obj.query
    let pathname=obj.pathname


    if(pathname=='/news'&&pathname!=='/favicon.ico'){
        res.end('aaa页面')
    } else if(pathname=='/books'&&pathname!=='/favicon.ico'){
        res.end('book页面')
    }else if(pathname=='/home'&&pathname!=='/favicon.ico'){
        console.log(1);
           //    let query={};
    // console.log(query)
    //    let obj=query;
    //    console.log(obj)

    if(query.name){
        res.write(JSON.stringify(query))

    }else {
        res.write('请输入参数')
    }
    res.end()
    }


})

server.listen(3002,()=>{
    console.log('3002 启动');
})